package com.java110.community.dao.impl;

import com.alibaba.fastjson.JSONObject;
import com.java110.community.dao.IRepairSettingServiceDao;
import com.java110.core.base.dao.BaseServiceDao;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.repair.RepairSettingDto;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.DAOException;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.vo.api.repair.StaffVo;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("repairSettingServiceDaoImpl")
public class RepairSettingServiceDaoImpl extends BaseServiceDao implements IRepairSettingServiceDao {
    private static Logger logger = LoggerFactory.getLogger(CommunityServiceDaoImpl.class);

    @Override
    public void saveRepairSetting(RepairSettingDto repairSettingDto) {
        repairSettingDto.setCreateTime(DateUtil.getCurrentDate());
        // 查询business_user 数据是否已经存在
        logger.debug("保存保修设置 入参 repairSettingDto : {}", repairSettingDto);
        int saveFlag = sqlSessionTemplate.insert("repairSettingServiceDaoImpl.saveRepairSetting", repairSettingDto);

        if (saveFlag < 1) {
            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "保存保修设置失败：" + JSONObject.toJSONString(repairSettingDto));
        }
    }

    @Override
    public List<RepairSettingDto> listRepairSettings(RepairSettingDto repairSettingDto) {
        List<RepairSettingDto> repairSettingDtos = sqlSessionTemplate.selectList("repairSettingServiceDaoImpl.listRepairSettings", repairSettingDto);
        return repairSettingDtos;
    }

    @Override
    public RepairSettingDto getOneById(Long id) {
        return sqlSessionTemplate.selectOne("repairSettingServiceDaoImpl.getOneById", id);
    }

    @Override
    public void updateRepairSetting(RepairSettingDto repairSettingDto) {
        sqlSessionTemplate.update("repairSettingServiceDaoImpl.updateRepairSetting", repairSettingDto);
    }

    @Override
    public void deleteRepairSetting(Long id) {
        sqlSessionTemplate.update("repairSettingServiceDaoImpl.deleteRepairSetting", id);
    }

    @Override
    public void saveRepairTypeUser(Map<String, Object> map) {
        map.put("createTime", DateUtil.getCurrentDate());
        sqlSessionTemplate.insert("repairSettingServiceDaoImpl.saveRepairTypeUser", map);
    }

    @Override
    public StaffVo getStaff(Long repairType, Long staffId) {
        Map map = new HashMap();
        map.put("repairType", repairType);
        map.put("staffId", staffId);
        return sqlSessionTemplate.selectOne("repairSettingServiceDaoImpl.getStaff", map);
    }


    @Override
    public List<StaffVo> listRepairTypeUsers(JSONObject reqJson) {
        Map<String, Object> map = reqJson.getInnerMap();
        return sqlSessionTemplate.selectList("repairSettingServiceDaoImpl.listRepairTypeUsers", map);
    }

}
